var db = require("./db"),
  mongoose = db.mongoose;
var Schema = mongoose.Schema;

var schema = new Schema({
  title: String,
  content: String,
  abstract: String,
  cate: { type: Number, default: 0 },
  user: { type: Schema.Types.ObjectId, ref: "user" }, //外链
  comments: [
    {
      commentUser: { type: Schema.Types.ObjectId, ref: "user" },
      commentContent: String
    }
  ], //子文档
  createTime: { type: Date, default: Date.now() },
  updateTime: { type: Date, default: Date.now() }
});

module.exports = mongoose.model("essay", schema, "essays");
